package platformio

import (
	"encoding/json"
	"os"
	"path/filepath"
)

// --

type LastCheck struct {
	PlatformioUpgrade uint64 `json:"platformio_upgrade"`
	PruneSystem       uint64 `json:"prune_system"`
}
type AppState struct {
	LastVersion string `json:"last_version"`
	LastCheck   `json:"last_check"`
	Cid         string `json:"cid"`
	CreatedAt   uint64 `json:"created_at"`
}

func LoadAppState() (state AppState) {
	b, err := os.ReadFile(filepath.Join(PLATFORM_IO_PREFIX, AppStateFile))
	if err != nil {
		return
	}

	err = json.Unmarshal(b, &state)
	if err != nil {
		return
	}

	return
}

// --
type Storage struct {
	RecentProjects []string    `json:"recentProjects"`
	RouteBadges    interface{} `json:"routeBadges"`
}

type HomeState struct {
	Storage `json:"storage"`
}

func LoadHomeState() (state HomeState) {
	b, err := os.ReadFile(filepath.Join(PLATFORM_IO_PREFIX, HomeStateFile))
	if err != nil {
		return
	}

	err = json.Unmarshal(b, &state)
	if err != nil {
		return
	}

	return
}
